﻿Imports System.Data.OleDb
Public Class frmCapNhatSoLuongTonKhoXuLy
#Region "Form Event"
    Public IDSanPham
    Private Sub frmCapNhatSoLuongTon_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim dbConn As New OleDb.OleDbConnection
            Dim dataAccess As New DataAccess
            Dim dsSanPham As New DataSet
            Dim dtSanPham As New DataTable
            Dim query As String = "Select * From SanPham Where IDSanPham=" & IDSanPham
            Dim adapter As OleDb.OleDbDataAdapter
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            adapter = New OleDb.OleDbDataAdapter(query, dbConn)
            adapter.Fill(dsSanPham)
            dbConn.Close()
            dtSanPham = dsSanPham.Tables(0)
            txtTenSanPham.Text = dtSanPham.Rows(0)("TenSanPham")
            txtMaSanPham.Text = dtSanPham.Rows(0)("MaSanPham")
            txtSoLuong.Text = dtSanPham.Rows(0)("SoLuongKhoXuLy")
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
#End Region
#Region "Button Event"
    'Cho nhập số lẻ
    Private Function IsDotted(ByVal KeyChar As Char) As Boolean
        Try
            If KeyChar = ","c Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception

        End Try
    End Function
    Private countComma As Integer = 0
    Private Sub txtSoLuong_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        txtSoLuong.BackColor = Color.White
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then
            e.Handled = True
        End If
        Dim s As String = txtSoLuong.Text
    End Sub
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Try
            If txtSoLuong.Text = "" Then
                txtSoLuong.BackColor = Color.FromArgb(192, 255, 255)
                txtSoLuong.Focus()
                Exit Sub
            End If
            Dim dataAccess As New DataAccess
            Dim dbConn As New OleDb.OleDbConnection
            Dim dbCommand As OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            Dim query As String = ""
            query = "Update SanPham Set SoLuongKhoXuLy=" & Single.Parse(txtSoLuong.Text.Trim) & ",NgaySuaGanNhat='" & NgayTao() & "',NguoiSuaGanNhat='" & NguoiTao() & "'  Where IDSanPham=" & IDSanPham
            dbCommand = New OleDbCommand(query, dbConn)
            dbCommand.ExecuteNonQuery()
            dbConn.Close()
            frmQuanLyKhoXuLy.SoLuongTonKho_Load_ByDate()
            Me.Close()
        Catch ex As Exception
            ShowError()
        End Try
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Try
            txtTenSanPham.Text = ""
            txtMaSanPham.Text = ""
            txtDonViTinh.Text = ""
            txtQuyCach.Text = ""
            txtSoLuong.Text = "0.00"
            Me.Close()
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
#End Region


End Class